/**
 * 
 */

package com.dat255.tentatime;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * 
 * @author daniel
 *
 */
public class FindActivityTwo extends Activity implements OnClickListener {
	//Textbox for course ID
	EditText editCourseID;
	//Textbox for course name
	EditText editCourseName;
	Button	buttonFind;
	
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.find);
        
        //Assign components
        editCourseID = (EditText) findViewById(R.id.editCourseID);
        editCourseName = (EditText) findViewById(R.id.editCourseName);
        buttonFind = (Button) findViewById(R.id.buttonFind);
        
        //Initiate listener
        buttonFind.setOnClickListener(this);
        
        
    }


/*
 * This method will run when the user presses the find button
 * @see android.view.View.OnClickListener#onClick(android.view.View)
 */
	@Override
	public void onClick(View v) {
		
		String cID = editCourseID.getText().toString();
		String cName = editCourseName.getText().toString();
		
	if(cID.length() == 0){
		Toast.makeText(this, "You need to enter a Course ID!", Toast.LENGTH_LONG).show();
	}
	if(cName.length()== 0){	
		Toast.makeText(this, "You need to entera a Course name!", Toast.LENGTH_LONG).show();
	}
		
	if(cName.length() > 0 && cID.length() > 0){
		Intent intent = new Intent(FindActivityTwo.this, TodosOverview.class);
	    intent.putExtra("coursename", cName);
	    intent.putExtra("courseid", cID);
	    FindActivityTwo.this.startActivity(intent); 
	}	
		
		
		Log.d("FindActivityTwo","onClick'd with"+" "+cID+" "+cName);
		
	}

	
	///////////// MENU

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}


	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		
		switch(item.getItemId()){
		
		case R.id.itemPrefs:
			startActivity(new Intent(this,PrefsActivity.class));
			break;
			
		case R.id.itemFind:
			startActivity(new Intent(this, FindActivity.class));
			break;
		
		
		
		}
		
		
		
		return true;
	}
	
	
}
